package dispatcher.gui.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.JTabbedPane;

import state.Globals;

import dispatcher.gui.GroupDispatcherView;

/**
 * This class is used as a listener for reconnecting to the group dispatcher server
 * @author Caleb
 *
 */
public class GroupDispatcherViewNetworkMenuItemListener implements ActionListener {

	private JTabbedPane pane;
	
	/**
	 * The main constructor
	 * @param pane The current pane when reconnect button was hit for pane specific reconnect
	 * functionality
	 */
	public GroupDispatcherViewNetworkMenuItemListener(JTabbedPane pane){
		this.pane = pane;
	}
	
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() instanceof JMenuItem){
			JMenuItem item = (JMenuItem)arg0.getSource();
			if (item.getText().equals("Reconnect")){
				if(pane.getSelectedIndex() == 0){
					Globals.getLogger().log("Reconnect GroupDispatcherView", this.getClass().getName(), "actionPerformed");
					
					GroupDispatcherView.getInstance().resetElevators();
					GroupDispatcherView.getInstance().reconnectToServer();
				}else if(pane.getSelectedIndex() == 1){
					Globals.getLogger().log("Reconnect PersonDispatcherView", this.getClass().getName(), "actionPerformed");
				}
			}
		}
	}

}
